package cn.wolfcode.luowowo.comment.service.impl;

import cn.wolfcode.luowowo.comment.domain.ItemShopComment;
import cn.wolfcode.luowowo.comment.domain.StrategyComment;
import cn.wolfcode.luowowo.comment.query.ItemShopCommentQueryObject;
import cn.wolfcode.luowowo.comment.repository.ItemShopCommentPageRepository;
import cn.wolfcode.luowowo.comment.repository.ItemShopCommentRepository;
import cn.wolfcode.luowowo.comment.service.IItemShopCommentService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.util.StringUtils;

@Service
public class ItemShopCommentServiceImpl implements IItemShopCommentService {

    @Autowired
    private ItemShopCommentRepository repository;

    @Autowired
    private ItemShopCommentPageRepository pageRepository;

    @Override
    public void addComment(ItemShopComment comment) {

        repository.insert(comment);
    }

    @Override
    public Page queryPageForComment(ItemShopCommentQueryObject qo) {

        Page<ItemShopComment> page = pageRepository.findAll(PageRequest.of(qo.getCurrentPage() - 1, qo.getPageSize(), new Sort(Sort.Direction.DESC, "date")));

        return page;
    }
}
